/**
 * outsider.com.cn Inc.
 * Copyright (c) 2011-2023 All Rights Reserved.
 */
package com.yuanmeng.common.core.handler;

import java.util.Date;

import com.yuanmeng.common.core.enums.ErrorCodeEnum;
import com.yuanmeng.common.core.exception.ServiceException;
import com.yuanmeng.common.core.utils.DateUtils;

/**
 * @author outsider
 * @version Id: DateValidateHandler.java, v 0.1 2023/4/12 11:21 outsider Exp $$
 */
public class DateValidateHandler {

    /**
     * 校验时间间隔多少天
     * @param startTime     开始时间
     * @param stopTime      结束时间
     * @param intervalNum   间隔天数
     */
    public static void timeIntervalValidate(Date startTime, Date stopTime, Long intervalNum) {
        if (startTime.after(stopTime)) {
            throw new ServiceException(ErrorCodeEnum.START_TIME_IS_AFTER_THE_END_TIME_ERROR);
        }

        Long intervalDay = DateUtils.calculateIntervalNum(startTime, stopTime);

        if (intervalDay > intervalNum) {
            throw new ServiceException("选择时间不能相差超过" + intervalNum + "天");
        }
    }
}